﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ExamSharedClasses;
using ExamSharedClasses.Commands;

namespace ExamClient
{
    /// <summary>
    /// (k) Der Frame, um eine Multiple-Choicefrage darzustellen
    /// </summary>
    public partial class QuestionTypeMultiplePage : Page {

        public AnswerTypeMultiple AnswerTypeMultiple { get; set; }
        public int Index { get; set; }

        public QuestionTypeMultiplePage( AnswerTypeMultiple answerTypeMultiple ) {
            InitializeComponent();
            this.AnswerTypeMultiple = answerTypeMultiple;
            UpdateWindow();
            answerCheckBox1.Focus();
        }

        public void UpdateWindow() {
            QuestionTypeMultiple questionTypeMultiple = ( QuestionTypeMultiple )AnswerTypeMultiple.AnswerQuestion;
            questionTextBlock.Text = questionTypeMultiple.QuestionBody;
            answerCheckBox1.Content = questionTypeMultiple.QuestionAnswer1;
            answerCheckBox2.Content = questionTypeMultiple.QuestionAnswer2;
            if ( questionTypeMultiple.QuestionAnswer3 != null && !( questionTypeMultiple.QuestionAnswer3.Equals( "" ) ) )
                answerCheckBox3.Content = questionTypeMultiple.QuestionAnswer3;
            else
                answerCheckBox3.IsEnabled = false;
            if ( ( questionTypeMultiple.QuestionAnswer4 != null && !( questionTypeMultiple.QuestionAnswer4.Equals( "" ) ) ) )
                answerCheckBox4.Content = questionTypeMultiple.QuestionAnswer4;
            else
                answerCheckBox4.IsEnabled = false;
        }

        private void answerButton_Click( object sender, RoutedEventArgs e ) {
            int summe = 0;
            summe += answerCheckBox1.IsChecked == true ? 1 : 0;
            summe += answerCheckBox2.IsChecked == true ? 2 : 0;
            summe += answerCheckBox3.IsChecked == true ? 4 : 0;
            summe += answerCheckBox4.IsChecked == true ? 8 : 0;
            AnswerTypeMultiple.AnswerUserAnswer = summe;
            AnswerTypeMultiple.AnswerUserId = App.UserAddress.UserId;
            passButton_Click( null, null );
        }

        private void passButton_Click( object sender, RoutedEventArgs e ) {
            App.ExamPage.BindNextPageToFrame();
        }

    }


}
